package com.heifeng.cloudshelf.push;

import android.content.Context;
import android.util.Log;


import java.util.HashSet;
import java.util.Set;

import cn.jpush.android.api.JPushInterface;

public class JpushUtils {

    public static int sequence = 100;

    public static void init(Context _context) {
        JPushInterface.setDebugMode(true);
        JPushInterface.init(_context);
    }

    public static void start(Context _context) {
        JPushInterface.init(_context);
        JPushInterface.resumePush(_context);
    }


    public static void setAlias(Context _context, String name) {
//        sequence = getSequence();
        Log.e("JpushUtils", "setAlias name:" + name+",sequence:"+sequence);
        JPushInterface.setAlias(_context,sequence,name);
        JPushInterface.setTags(_context, sequence, setUserTags(name));
//        TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
//        sequence++;
//        tagAliasBean.action = TagAliasOperatorHelper.ACTION_SET;
//        tagAliasBean.alias = name;
//        tagAliasBean.isAliasAction = true;
//        TagAliasOperatorHelper.getInstance().handleAction(_context, sequence, tagAliasBean);
    }

    //设置标签（同上）

    private static Set<String> setUserTags(String name) {
        //添加3个标签用户（获取登录userid较为常见）
        Set<String> tags = new HashSet<>();
        tags.add(name);
        return tags;
    }

    private static int getSequence() {
        int c = (int) (Math.random() * 1000);
        if (100 < c) {
            return getSequence();
        }
        return c;
    }
}
